from importlib import reload

import scrapy
import sys

reload(sys)


class BookSpider(scrapy.Spider):
    scrapy.Spider.name = 'biQuGe'
    scrapy.Spider.start_urls = ['http://www.xbiquge.la/10/10489/4534454.html']

    def parse(self, response):
        title = response.css('#wrapper > div.content_read > div > div.bookname > h1').get()
        content = response.xpath('//*[@id="content"]').get()
        next_page = response.css('div.bottem2 > a:nth-child(4)::attr("href")').get()
        next_page = response.urljoin(next_page)
        yield {
            'title': title,
            'content': content
        }
        if next_page is not None:
            scrapy.Request(next_page, self.parse)
